import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { router } from "./router"
import App from './App.vue'
import store from './store'
import "./permission"
import 'virtual:windi.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import "nprogress/nprogress.css"
import "video.js/dist/video-js.css";
import zhCn from "element-plus/es/locale/lang/zh-cn"

zhCn.el.pagination.total = "共" + `{total}` + "条"
zhCn.el.pagination.goto = "跳转至"

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(ElementPlus,{locale:zhCn});
app.use(router)
app.use(store)

// 在应用挂载前获取配置
fetch('http://172.16.1.228:9100/api/config/getConfig')
    .then(response => response.json())
    .then(data => {
        console.log('配置响应数据:', data);

        if (data.code === '200' && data.data) {
            // 直接使用 data.data 对象，不是数组
            store.state.config = data.data;
            console.log('配置已存储：', store.state.config);

            // 动态设置页面标题
            if (data.data.topName) {
                document.title = data.data.topName;
                console.log('页面标题已设置为:', data.data.topName);
            }
        }
    })
    .catch(error => {
        console.error('获取配置失败：', error);
        // 设置默认标题作为备选
        document.title = '救护消防应急救援中心微课系统';
    })
    .finally(() => {
        // 确保配置获取完成后才挂载应用
        app.mount('#app');
    });
